﻿Imports System.Data.OleDb
Public Class frmThemNhanVienTiepThi
#Region "Form Event"
    Public NhanVienTiepThiId As Integer = -1
    Private Sub frmTinhThanh_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            txtMaNhanVienTiepThi.Text = ""
            txtTenNhanVienTiepThi.Text = ""
            txtGhiChu.Text = ""
            If NhanVienTiepThiId <> -1 Then
                Dim dbConn As New OleDb.OleDbConnection
                Dim dataAccess As New DataAccess
                Dim dsNhanVienTiepThi As New DataSet
                Dim dtNhanVienTiepThi As New DataTable
                Dim query As String = "Select MaNhanVienTiepThi,TenNhanVienTiepThi,GhiChu From NhanVienTiepThi Where NhanVienTiepThiId=" & NhanVienTiepThiId
                Dim adapter As OleDb.OleDbDataAdapter
                dataAccess.ConnectDatabase_DBAccess(dbConn)
                adapter = New OleDb.OleDbDataAdapter(query, dbConn)
                adapter.Fill(dsNhanVienTiepThi)
                dbConn.Close()
                dtNhanVienTiepThi = dsNhanVienTiepThi.Tables(0)
                txtMaNhanVienTiepThi.Text = dtNhanVienTiepThi.Rows(0)("MaNhanVienTiepThi")
                txtTenNhanVienTiepThi.Text = dtNhanVienTiepThi.Rows(0)("TenNhanVienTiepThi")
                txtGhiChu.Text = dtNhanVienTiepThi.Rows(0)("GhiChu")
            End If
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
#End Region
#Region "Button Event"

    

    
#End Region
#Region "Load Data"
   
#End Region
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Try
            If txtMaNhanVienTiepThi.Text = "" Then
                txtMaNhanVienTiepThi.BackColor = Color.FromArgb(192, 255, 255)
                Exit Sub
            Else
                txtMaNhanVienTiepThi.BackColor = Color.White
            End If
            If txtTenNhanVienTiepThi.Text = "" Then
                txtTenNhanVienTiepThi.BackColor = Color.FromArgb(192, 255, 255)
                Exit Sub
            Else
                txtMaNhanVienTiepThi.BackColor = Color.White
            End If
            Dim dataAccess As New DataAccess
            Dim dbConn As New OleDb.OleDbConnection
            Dim dbCommand As OleDbCommand
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            Dim query As String = ""
            If NhanVienTiepThiId = -1 Then
                query = String.Format("Insert Into NhanVienTiepThi(MaNhanVienTiepThi,TenNhanVienTiepThi,GhiChu) Values(N'{0}',N'{1}',N'{2}')", txtMaNhanVienTiepThi.Text, txtTenNhanVienTiepThi.Text, txtGhiChu.Text)
            Else
                query = String.Format("Update NhanVienTiepThi Set MaNhanVienTiepThi=N'{0}',TenNhanVienTiepThi=N'{1}',GhiChu=N'{2}' Where NhanVienTiepThiId={3}", txtMaNhanVienTiepThi.Text, txtTenNhanVienTiepThi.Text, txtGhiChu.Text, NhanVienTiepThiId)
            End If
            dbCommand = New OleDbCommand(query, dbConn)
            dbCommand.ExecuteNonQuery()
            dbConn.Close()
            txtMaNhanVienTiepThi.Text = ""
            txtTenNhanVienTiepThi.Text = ""
            txtGhiChu.Text = ""
            frmNhanVienTiepThi.NhanVienTiepThi_Load()
            If NhanVienTiepThiId <> -1 Then
                Me.Close()
            End If
        Catch ex As Exception
            ShowError()
        End Try
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Try
            txtMaNhanVienTiepThi.Text = ""
            txtTenNhanVienTiepThi.Text = ""
            txtGhiChu.Text = ""
            Me.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Sub

    
    Private Sub txtMaNhanVienTiepThi_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMaNhanVienTiepThi.KeyUp
        Try
            txtMaNhanVienTiepThi.BackColor = Color.White
        Catch ex As Exception

        End Try
    End Sub

    Private Sub txtTenNhanVienTiepThi_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTenNhanVienTiepThi.KeyUp
        Try
            txtTenNhanVienTiepThi.BackColor = Color.White
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
End Class